package fylder.chat;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;


import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * base activity
 * Created by fylder on 15-6-18.
 */
public abstract class BaseAppCompatActivity extends AppCompatActivity {

    protected Context mContext;

    @Bind(R.id.toolbar)
    protected Toolbar toolbar;
    @Bind(R.id.toolbar_title)
    protected TextView titleText;
    @Bind(R.id.toolbar_menu)
    protected TextView menuTextView;

    protected MenuItem doneMenuItem;

    //  private boolean isShowMenu = false;
    //  private String menuText = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(setLayoutView());
        //  ButterKnife.inject(this);
        ButterKnife.bind(this);
        mContext = BaseAppCompatActivity.this;
        initTool();
        init();

    }

    private void initTool() {
        if (toolbar == null) {
            return;
        }
        toolbar.setTitle("");
        setSupportActionBar(toolbar);
        toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        initToolbar();
    }


    /**
     * 初始化menu配置
     *
     * @param title  标题内容
     * @param isShow 是否显示
     * @param text   文字内容
     */
    protected void setToolText(String title, boolean isShow, String text) {
        titleText.setText(title);

        // isShowMenu = isShow;
        if (text == null) {
            text = "";
        }
        if (isShow) {
            menuTextView.setText(text);
            menuTextView.setVisibility(View.VISIBLE);
            menuTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onClickMenu();
                }
            });
        } else {
            menuTextView.setVisibility(View.GONE);
        }
    }

    /**
     * 右边点击事件
     */
    protected void onClickMenu() {
        // Toast.makeText(BaseAppCompatActivity.this, "click", Toast.LENGTH_SHORT).show();
    }


    /**
     * 布局
     *
     * @return
     */
    public abstract int setLayoutView();

    protected abstract void initToolbar();

    public abstract void init();


}
